package com.vijay.aspect;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;

import java.util.Arrays;

@Aspect
public class ServiceAspect {


    @Pointcut("execution(public * com.vijay.service.*.*(..))")
    public void pointCut() {

    }

    @Before("pointCut()")
    public void before(JoinPoint jp) {

        Signature signature = jp.getSignature();

        System.out.println("signature::" + signature.getName());

        Object[] args = jp.getArgs();

        System.out.println("method args::" + Arrays.toString(args));

        System.out.println("before advice.....");


    }

    @After("pointCut()")
    public void after() {

        System.out.println("after advice");

    }

    @AfterReturning(value = "pointCut()", returning = "result")
    public void afterReturning(JoinPoint jp, Object result) {
        System.out.printf("[ServiceAspect]切面 [返回通知afterReturning] 打印结果 -> result:%s%n", result);
    }

    @AfterThrowing(value = "pointCut()", throwing = "e")
    public void afterThrowing(JoinPoint jp, Throwable e) {


        System.out.println("[ServiceAspect]切面 [afterThrowing]");

    }

    @Around(value = "pointCut()")
    public void around(ProceedingJoinPoint pjp) throws Throwable {
        System.out.println("[ServiceAspect]切面 [around before]");

        Object proceed = pjp.proceed();

        System.out.println("[ServiceAspect]切面 [around after]");
    }

}
